#!/bin/bash

echo "Welcome to CloudDoor Installer."
# echo "auto eth0" >> /etc/network/interfaces
cp /etc/apt/sources.list /etc/apt/sources.list_backup
sudo rm -rf /etc/apt/sources.list
echo "deb http://mirrors.ustc.edu.cn/ubuntu-ports/ bionic-security main restricted universe multiverse" >> /etc/apt/sources.list
echo "deb http://mirrors.ustc.edu.cn/ubuntu-ports/ bionic-updates main restricted universe multiverse" >> /etc/apt/sources.list
echo "deb http://mirrors.ustc.edu.cn/ubuntu-ports/ bionic-backports main restricted universe multiverse" >> /etc/apt/sources.list

cd /root/
echo "install libevent"
myPath="/root/libevent-2.0.21-stable.tar.gz"
echo "libevent file check"
if [ ! -f "$myPath" ]; then
   echo "libevent error python"
   wget https://github.com/downloads/libevent/libevent/libevent-2.0.21-stable.tar.gz
fi
cd /root/
tar zxvf libevent-2.0.21-stable.tar.gz
cd libevent-2.0.21-stable
./configure -prefix=/usr
echo "install make libevent"
make
make install

sudo apt-get install wpasupplicant

echo "auto eth0" >> /etc/network/interfaces
echo "iface eth0 inet dhcp" >> /etc/network/interfaces
echo "auto wlan0" >> /etc/network/interfaces
echo "iface wlan0 inet dhcp" >> /etc/network/interfaces
echo "wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf" >> /etc/network/interfaces
chmod 755 /etc/network/interfaces
chmod 755 /etc/wpa_supplicant

mkdir /root/CloudDoor/

#sudo touch /usr/local/bin/door-start
#sudo chmod -R 777 /usr/local/bin/door-start
#echo "cd $PWD" >> /usr/local/bin/door-start
#echo "cp /root/CloudDoorGit/CloudDoor /root/CloudDoor/" >> /usr/local/bin/door-start
#echo "cd /root/CloudDoor/" >> /usr/local/bin/door-start
#echo "chmod -R 777 CloudDoor" >> /usr/local/bin/door-start
#echo "./CloudDoor" >> /usr/local/bin/door-start
# echo "git clone https://gitee.com/ahnu119/CloudDoorGit.git" >> /usr/local/bin/door-start
sudo touch /usr/local/bin/door-start
sudo chmod -R 777 /usr/local/bin/door-start
echo "cd $PWD" >> /usr/local/bin/door-start
echo "cd /root/cloud-door-liunx/" >> /usr/local/bin/door-start
# echo "chmod -R 777 cloud-door-liunx" >> /usr/local/bin/door-start
echo "python3 CloudDoor.py" >> /usr/local/bin/door-start

sed -i -e '$i \/usr/local/bin/door-start\n' /etc/rc.local
sudo chmod -R 777 /usr/local/bin/door-start

sudo cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

reboot